#include<stdio.h>
#include<conio.h>
typedef struct Ball{
    char type;
    long count,start;
};
typedef struct Node{
    char type;
    long next,pre;
};
/************************* Bien ****************/
Node list[500001];long listNum=0;
Ball temp[500001];long tempCount=-1;
Ball tree[1100000];long count=0,m;
void input(){
    char ch,last=0;
    long count=0;
    FILE *fp=fopen("BALGAME3.INP","r");
    while(!feof(fp)){
        fscanf(fp,"%c",&ch);
        list[listNum].type=ch;
        list[listNum].next=++listNum;
        if(ch!=last){
            if(tempCount==-1)tempCount++;
            else temp[tempCount++].count=count;
            temp[tempCount].start=listNum;
            temp[tempCount].type=ch;
            count=1;
            last=ch;
        }else count++;
    };
    temp[tempCount++].count=count-1;
    list[listNum].next=-1;
    fclose(fp);
}
long createm(long n){
    n--;
    long i=1;
    while(n>0){
        n>>=1;
        i<<=1;
    }
    return i;
}
long max(long a,long b){
    return a>b?a:b;
}
void update(long index,long newValue){
    long i=index+m;
    tree[i]=newValue;
    while(i>0){
        if(tree[i].count>=tree[i^1].count){
            tree[i/2].count=tree[i].count;
            tree[i/2].start
    
void createIntevalTree(){
    long i,j;
    for(i=0;i<tempCount;i++)printf("(%c : %d -> %d)\n",temp[i].type,temp[i].start,temp[i].count);
    count=tempCount;
    m=createm(count);
    for(i=0;i<count;i++){
        tree[i+m].type=temp[i].type;
        tree[i+m].start=temp[i].start;
        tree[i+m].count=temp[i].count;
    }
    j=m;
    do{
        j=j/2;
        for(i=0;i<j;i++)
            if(tree[2*(i+j)].count<tree[2*(i+j)+1].count){
                tree[i+j].count=tree[2*(i+j)+1].count;
                if(j==m/2)tree[i+j].start=2*(i+j)+1-m;
                else tree[i+j].start=tree[2*(i+j)+1].start;
            }else{
                tree[i+j].count=tree[2*(i+j)].count;
                tree[i+j].start=tree[2*(i+j)].start;
                if(j==m/2)tree[i+j].start=2*(i+j)-m;
                else tree[i+j].start=tree[2*(i+j)].start;
            }
    }while(j>1);
    for(i=1;i<m+count;i++)printf("%d ",tree[i].count);
    printf("-->%d",tree[1].start);
}

int main(){
    input();
    createIntevalTree();
    getch();
    return 0;
}
